# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=twisted-iocpsupport
_pyname=twisted_iocpsupport
pkgbase=mingw-w64-python-${_pyname}
pkgname=${MINGW_PACKAGE_PREFIX}-python-${_pyname}
pkgver=1.0.4
pkgrel=1
pkgdesc='An extension for use in the twisted I/O Completion Ports reactor (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
license=('MIT')
url='https://github.com/twisted/twisted-iocpsupport'
depends=(${MINGW_PACKAGE_PREFIX}-python)
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-wheel"
             "${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        001-fix-multiple-defs.patch)
sha256sums=('858096c0d15e33f15ac157f455d8f86f2f2cdd223963e58c0f682a3af8362d89'
            '615fe6e1ee621eafc69faefcada30258eb0692df44afac7020c29bf1555de958')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/001-fix-multiple-defs.patch

  rm -rf "${srcdir}"/python-build-${MSYSTEM} | true
  cp -r "${srcdir}/${_realname}-${pkgver}" "${srcdir}/python-build-${MSYSTEM}"
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  CFLAGS+=" -Wno-int-conversion"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_pyname}/LICENSE"
}
